//package yhao.infra.service.datasource;

//import org.hibernate.jpa.HibernatePersistenceProvider;
//import org.springframework.context.annotation.AnnotationConfigApplicationContext;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.orm.jpa.vendor.Database;
//import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
//import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
//
//import javax.persistence.EntityManagerFactory;
//import java.util.Properties;
//
///**
// * Jpa配置
// *
// * @author yoara
// */
//
//@Configuration
//public class JpaConfiguration {
//    @Bean(name="entityManagerFactory")
//    public EntityManagerFactory entityManagerFactory() {
//        LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
//        AnnotationConfigApplicationContext config = new AnnotationConfigApplicationContext(MysqlConfiguration.class);
//        bean.setDataSource(config.getBean("mysqlDataSource",DynamicDataSource.class));
//
//        //用于指定持久化实现厂商类
//        HibernatePersistenceProvider persistenceProvider = new HibernatePersistenceProvider();
//        bean.setPersistenceProvider(persistenceProvider);
//
//        //用于设置JPA实现厂商的特定属性
//        HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
//        jpaVendorAdapter.setGenerateDdl(false);
//        jpaVendorAdapter.setShowSql(true);
//        jpaVendorAdapter.setDatabase(Database.MYSQL);
//        bean.setJpaVendorAdapter(jpaVendorAdapter);
//        //扫描包
//        bean.setPackagesToScan("yhao.infra.service");
//        //用于指定一些高级特性
//        bean.setJpaDialect(new HibernateJpaDialect());
//        //其他参数
//        Properties jpaProperties = new Properties();
//        jpaProperties.put("hibernate.dialect","org.hibernate.dialect.MySQL5Dialect");
//        bean.setJpaProperties(jpaProperties);
//
//        return bean.getObject();
//    }
//}
